package com.zzyl.common.AI;

import com.baidubce.qianfan.Qianfan;
import com.baidubce.qianfan.core.auth.Auth;
import com.baidubce.qianfan.model.chat.ChatResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
public class AIInvokerUtil {
    @Autowired
    private AIModelProperties aiModelProperties;
    public String QianFanAI(String prompt){
        ChatResponse qianfan = new Qianfan(Auth.TYPE_OAUTH, aiModelProperties.getAccessKey(), aiModelProperties.getSecretKey())
                .chatCompletion()// 聊天接口
                .model(aiModelProperties.getModel())// 模型名称
                .addMessage("user",prompt)//
                .temperature(0.7)//自定义超参数值越大结果越随机
                .topP(1.0)
                .maxOutputTokens(2048)// 最大输出长度
                .responseFormat("json_object")// 输出格式为json
                .execute();
       return qianfan.getResult();
    }

}
